// src/services/login.ts

import type { TokenResult, UserInfoResult } from '@/types/member'
import { http } from '@/utils/http'

type LoginParams = {
  code: string
  encryptedData: string | null
  iv: string | null
}
type UserInfoParams = {
  encryptedData: string
  iv: string
  openid: string
  sessionKey: string
}

/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: LoginParams) => {
  return http<TokenResult>({
    method: 'POST',
    url: '/auth/webchat/login',
    data,
  })
}
export const postDriverLoginWxMinAPI = (data: LoginParams) => {
  return http<TokenResult>({
    method: 'POST',
    url: '/auth/webchat/driverLogin',
    data,
  })
}

export const postUserinfoAPI = (data: UserInfoParams) => {
  return http<UserInfoResult>({
    method: 'POST',
    url: '/sys/webchat/userinfo',
    data,
  })
}
export const driverUserinfoAPI = (data: UserInfoParams) => {
  return http<UserInfoResult>({
    method: 'POST',
    url: '/sys/webchat/driverUserinfo',
    data,
  })
}
